# 分页爬取58同城的租房信息
from bs4 import BeautifulSoup
import urllib.request
import re

url = 'http://bj.58.com/dashanzi/chuzu/pn1/?ClickID=1'

req = urllib.request.Request(url)

res = urllib.request.urlopen(req)

html = res.read()

bs = BeautifulSoup(html, 'lxml')

a = bs.find_all('div', class_='des')
# b=a.find_all
b = 0
for i in a:
    print('第' + str(b + 1) + '条数据：')
    print('标题：' + i.find('a').get_text().strip())
    print('图片地址：' + i.find_previous_sibling('div').find('img')['lazy_src'])
    print('户型：' + i.find('p', class_='room').get_text().strip().split(' ')[0])
    print('价格：' + i.find_next_sibling('div').find('b').get_text() + ' 元/月')
    print('*' * 80)
    b = b + 1
